Profiler
Profiler to time actions in your code with context.
Profiler is a tiny library to time functions in your Node.js code with context, so that you can present related actions after they have been completed.
Table of contents
Usage
Install the package from the npm registry as follows:
npm i @adonisjs/profiler
yarn add @adonisjs/profiler
and then use it as follows
import { Profiler } from '@adonisjs/profiler/build/standalone'
const profiler = new Profiler({
enabled: true,
whitelist: [],
blacklist: [],
})
Usage with AdonisJs
The @adonisjs/core
module includes this module by default. However, here's how you can set it up manually.
const providers = [
'@adonisjs/profiler/build/providers/ProfilerProvider'
]
And then also register the typings file inside tsconfig.json
file.
{
"files": ["./node_modules/@adonisjs/profiler/build/adonis-typings/profiler.d.ts"]
}
You will need only one instance of the profiler in your entire application and then you will work with rows
and actions
to time function calls.
Subscriber
The profiling data is delivered to a subscriber function and then subscriber can decide the storage or representation of data.
profiler.subscribe((packet) => {
})
You can only have one subscriber listening for profiler packets at a given time. This is done for the simplicitiy and performance, since we want the profiler to have minimum overhead to your applications.
White/blacklisting
The scope of profiling should always trim down as your application get mature, in that scanerio, instead of removing profiler calls, you can blacklist or whitelist actions and they will result in noop. For example:
const profiler = new Profiler({
enabled: true,
whitelist: [],
blacklist: ['find:route'],
})
const row = profile.create('http:request', { url: '/' })
row.profile('find:route', {}, () => {
})
Without changing anything in your code, the find:route
action will have no impact. If you will blacklist a row label, then all of it's actions will be disabled as well.
API Docs
Following are the autogenerated files via Typedoc
Maintainers
Harminder virk